/**
 * Moondance UML modeling tool
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.model;

import org.eclipse.swt.graphics.Image;
import java.util.ArrayList;

public class UMLRegion extends UMLEntity {
	private static final long serialVersionUID = -2900616010198889077L;
	private String name;
	private UMLCompositeState CompositeState;
	private ArrayList<UMLState> states;
	private static final Image ICON = createImage("icons/state/region_small.gif");
	@SuppressWarnings("unused")
	private ModelElement parent;

	public UMLRegion() {
		super();
		this.states = new ArrayList<UMLState>();
	}

	public UMLRegion(String name) {
		super();
		this.name = name;
		this.states = new ArrayList<UMLState>();
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public Image getIcon() {
		return ICON;
	}

	public String getLabelText() {
		String labelText = " <<region>> ";
		labelText += name + " ";
		return labelText;
	}

	public String toString() {
		return name;
	}

	public void setCompositeState(UMLCompositeState cs) {
		this.CompositeState = cs;
	}

	public UMLCompositeState getCompositeState() {
		return CompositeState;
	}

	public ArrayList<UMLState> getStates() {
		return states;
	}

	public boolean equals(Object o) {
		if (o == null || !(o instanceof UMLRegion))
			return false;
		UMLRegion c = (UMLRegion) o;
		String text1 = getLabelText();
		String text2 = c.getLabelText();
		return text1.equals(text2);
	}

	public boolean addState(UMLState newState) {
		if (!states.contains(newState)) {
			states.add(newState);
			firePropertyChange(CHILD, null, newState);
			return true;
		}
		return false;
	}

	public boolean removeState(UMLState newState) {
		if (states.remove(newState)) {
			firePropertyChange(CHILD, newState, null);
			return true;
		}
		return false;
	}

	public void setParent(ModelElement parent) {
		this.parent = parent;
	}

}
